#!/usr/bin/env python3

# this is a client to test the server[pong]

import sys

from PyQt5.QtCore import QCoreApplication
from PyQt5.QtDBus import QDBusConnection, QDBusInterface, QDBusReply

import PyQt5.QtDBus as dbus

if __name__ == '__main__':
    app = QCoreApplication(sys.argv)
    bus = QDBusConnection.sessionBus()
    if not bus.isConnected():
        raise Exception("Fail to connect to Session-Bus.")

    # get the proxy-interface object of the object-path
    iface = QDBusInterface('org.i5os.QtDBus.iodebugging', "/", 
                            # 'iodebugging.test.interface', 
                            "local.server.py.Server",
                            bus)
    if not iface.isValid():
        raise Exception("Fail to get the interface.")

    # method call
    # msg = iface.call("test_method_without_params")
    # msg = iface.call('test_method', sys.argv[1] if len(sys.argv) > 1 else "Default...")
    msg = iface.call("switch_page", "编辑页面")
    if not QDBusReply(msg).isValid():
        raise Exception("Fail to get the response.")

    print("iface return: ", QDBusReply(msg).value())
    app.exit()
